<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <script src="../wh2114/vuedemo/lib/vue.js"></script>
  </head>
  <body>
    <div id="app">
      <h2>{{title}}</h2>
      <h2 v-if="flag">Vue is awesome</h2>
      <h2 v-else>Vue is so easy?</h2>
      <button @click="flag=!flag">点击切换</button>
      <template v-if="ok">
        <h1>Title</h1>
        <p>Paragraph 1</p>
        <p>Paragraph 2</p>
      </template>
      <div>
        <h2>你的分数等级</h2>
        <h2 v-if="score>90">A</h2>
        <h2 v-else-if="score>80">B</h2>
        <h2 v-else-if="score>70">C</h2>
        <h2 v-else-if="score>60">D</h2>
        <h2 v-else>E(不及格)</h2>
      </div>
      <div v-show="show" @click="show=!show">
        v-show 的元素始终会被渲染并保留在 DOM 中。v-show 只是简单地切换元素的
        CSS property display
      </div>
      <div v-if="obj.person">
        <h2>v-if 经典用法 (ajax的异步数据)</h2>
        <h2>username -- {{obj.person.username }}</h2>
        <h2>word -- {{obj.person.word }}</h2>
      </div>
    </div>
    <script>
      const vm = new Vue({
        data: {
          title: "v-if & v-show 条件渲染",
          flag: true,
          ok: true,
          score: 99,
          show: true,
          obj: {},
        },
        methods: {},
        mounted() {
          document.getElementsByTagName("title")[0].innerHTML = this.title;
          setTimeout(() => {
            // 模拟ajax
            this.obj = {
              person: {
                age: 18,
                username: "zuozuomu",
                word: "2114-dayadyup",
              },
            };
          }, 2000);
        },
      }).$mount("#app");
    </script>
  </body>
</html>
